package com.vf.admin.client.controller.charging;

import com.vf.admin.client.common.ClientBaseController;
import com.vf.admin.client.common.ClientConstants;
import com.vf.admin.client.common.RedisKeys;
import com.vf.admin.client.service.AppUserService;
import com.vf.admin.common.entity.Result;
import com.vf.admin.miaodong.entity.AppUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;

/**
 * <p>Title : </p>
 * <p>Description : </p>
 * <p>DevelopTools : IDEA</p>
 * <p>DevelopSystem : Windows11</p>
 *
 * @Author : zxw
 * @Date 2023/8/28 19:23
 */
@Controller
@RequestMapping(value = "/api/charging")
public class ChargingController extends ClientBaseController {

    @Autowired
    AppUserService appUserService;


    @RequestMapping("/upDiamonds")
    @ResponseBody
    public Result upDiamonds(BigDecimal diamonds) {
        //获取当前登录用户的user对象
        Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
        AppUser appUser = appUserService.get(userId);

        boolean b = appUser.getDiamonds().compareTo(diamonds) >= 0;
        if (b){
        appUserService.upJianZuanShi(userId, diamonds);
        return this.sucessJSON("成功");
        }
        return this.errorJSON("余额不足");
//        return this.sucessJSON(b);

//        if (appUser.getDiamonds().compareTo(diamonds) > 0) {
//            return this.errorJSON("余额不足");
//        }

    }

}
